import { Component } from "@angular/core";
import {RegisterServices} from "../../../app/services/http.register.services";


@Component({
    selector:"login",
    templateUrl:"app/pages/login/login.html",
    styleUrls:["app/pages/login/login.scss"],
    providers:[RegisterServices]
})

export class Login{

    private model ={"username":"","password":""};
    private currentUserName:string;
    constructor(
        private registerServices :RegisterServices
    ){}

    onSubmit(){
        this.registerServices.sendCredentials(this.model).subscribe(data=>{

            window.localStorage.setItem("token",JSON.parse(JSON.stringify(data))['_body']);
            this.registerServices.sendToken(window.localStorage.getItem("token")).subscribe(data=>{
                this.currentUserName = this.model.username;
                window.localStorage.setItem("currentUserName",this.model.username);
                this.currentUserName = this.model.username;
                this.model.username="";
                this.model.password="";

            })
        })
    }

}